package create_album;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
 * 
 * @author lyos2210
 *
 */
@SuppressWarnings("serial")
public class AlbumView { //extends JFrame{

	private JFrame frame = null;
	private ArrayList<String> ArrayListPath = null;
	
	public ArrayList<String> getArrayListPath() {
		return ArrayListPath;
	}

	public void setArrayListPath(ArrayList<String> toto) {
		this.ArrayListPath = toto;
	}


//	public void sauverJPanelDansFile(JPanel panneauImage, File fichier)
//			throws IOException{
//				BufferedImage tamponSauvegarde = new BufferedImage(
//						panneauImage.getPreferredSize().width,
//						panneauImage.getPreferredSize().height,
//						BufferedImage.TYPE_3BYTE_BGR);
//				Graphics g = tamponSauvegarde.getGraphics();
//				g.setColor(Color.GRAY);
//				g.fillRect(0, 0, panneauImage.getPreferredSize().width,
//						panneauImage.getPreferredSize().height);
//				panneauImage.paint(g);
//				ImageIO.write(tamponSauvegarde, "JPG", fichier);
//			}
	 
//	 public void CreateFileJPanel(ArrayList<String> path , int value)
//	 {
//		 JPanel pan = new JPanel(new FlowLayout());
//		 for (int i = 0; i < path.size(); i++)
//		 {
//			 try {
//				JLabel lab = new JLabel(new ImageIcon(ImageIO.read(new File(path.get(i)))));
//				pan.add(lab);
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		 }
//			 try {
//				sauverJPanelDansFile(pan, new File ("Album_"+value+".jpg"));
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//	 }
	 
	 //ideale serai de creer un tableau de Jlist contenant 5 elements de toto par liste
	 //et le faire pour tt les elts de toto
	 //actuellement l creer un list contenant toutes les element de toto
	public DefaultListModel createList()
	{
	        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	        DefaultListModel listModel = new DefaultListModel();
	        int count = 0;
	        for (int i = 0; i < ArrayListPath.size(); i++)
	        {
	        	  ImageIcon ii = null;
				try {
					Image img = ImageIO.read(new File(ArrayListPath.get(i)));
					//redimensionner les images
					Image scaleImg = img.getScaledInstance(150, -1, Image.SCALE_FAST);
					ii = new ImageIcon(scaleImg);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	                listModel.add(count++, ii);
	        }       
			return listModel;
	}
	
	public void createView() {
		frame = new JFrame();
		frame.setTitle("Album View");
		frame.setBackground(Color.GRAY);
		frame.setLocation(200, 200);
		frame.setSize(600, 500);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		//recupere la liste creer 
		JList list = new JList(createList());
		list.setLayoutOrientation(JList.VERTICAL_WRAP);
        list.setVisibleRowCount(-8);
        //ajoute la list a la frame
        frame.setLayout(new GridLayout(2,1));
        frame.add(new JScrollPane(list),BorderLayout.CENTER);
		JPanel panBoutton = new JPanel();
		panBoutton.setMaximumSize(new Dimension(600,50));
		panBoutton.setLayout(new FlowLayout());
		JButton fermer = new JButton("fermer fenetre");
		fermer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
//		frame.add(fermer,BorderLayout.SOUTH);
		panBoutton.add(fermer);
		frame.add(panBoutton, BorderLayout.SOUTH);
//		frame.pack();
		 frame.setVisible(true);
 	}
}
